if (!MoodDlg) {
   var MoodDlg = {
      init: function() {
         this.mood_desc = document.getElementById('mood_desc');
         this.mood_rate = document.getElementById('mood_rate');
         this.mood_url = document.getElementById('mood_url');
         this.reset();
      },
      reset: function() {
         this.setMood(window.arguments[0].input.rate);
         this.mood_url.value = '';//'http://moodmill.com';
         this.mood_desc.value = '';
      },
      submit: function() {
        Logger.log("about to submit darn: " + this.mood_desc.value);
         if (this.canSubmit()) {
            Logger.log("submitting");
            window.arguments[0].output = {'rate': this.mood_rate.value, 'desc': this.mood_desc.value, 'url': this.mood_url.value};
            window.close();
         } Logger.log("cannot submit");
      },
      setMood: function(rate) {
         this.mood_rate.selectedIndex = rate-1;
         Logger.log('setMood: ' + rate);
      },
      canSubmit: function() {
        //alert("can submit: " + this.mood_desc.value);
        Logger.log("can submit: " + this.mood_desc.value);
        if (/^\s*$/.test(this.mood_desc.value)) {
            alert("You cannot leave description empty");
            Logger.log("You cannot leave description empty")
            return false;
        } else {
            //alert("canSubmit allrite");
            return true;
        }
      }
   }
}

window.addEventListener("load", function(e) { MoodDlg.init(); }, false);